package main

import (
	"fmt"

	"gitee.com/xiarrunliang/go-learning/learn_begin/grammarLearn"
	"github.com/davyxu/cellnet"
	"github.com/davyxu/cellnet/peer"
	_ "github.com/davyxu/cellnet/peer/tcp"
	"github.com/davyxu/cellnet/proc"
	_ "github.com/davyxu/cellnet/proc/tcp"
)

const (
	Black int = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

func PrintWithColor(s string, color int) {
	fmt.Printf("\x1b[1;%dm%s\x1b[0m\n", color, s)
}

func main() {
	PrintWithColor("hello world!", Magenta)

	//errgrouplearn.Run()

	grammarLearn.Run()

	mainRunPassParam()
}

func mainRunNewEventQueue() {
	// 创建事件队列
	queue := cellnet.NewEventQueue()

	// 创建 TCP 服务器
	p := peer.NewGenericPeer("tcp.Acceptor", "server", "127.0.0.1:8888", queue)

	// 绑定消息处理逻辑
	proc.BindProcessorHandler(p, "tcp.ltv", func(ev cellnet.Event) {
		switch msg := ev.Message().(type) {
		case *cellnet.SessionAccepted:
			fmt.Println("Client connected")
		case *cellnet.SessionClosed:
			fmt.Println("Client disconnected")
		case []byte:
			fmt.Printf("Received: %s\n", string(msg))
			ev.Session().Send([]byte("Hello, client!"))
		}
	})

	// 启动服务器
	p.Start()
	queue.StartLoop()
	queue.Wait()
}

type User struct {
	name string
}
type Manager struct {
	User
	title string
}

func functttt() {
	m := Manager{
		User:  User{"Tom"}, // 匿名字段的显式字段名，和类型名相同。
		title: "Administrator",
	}
	fmt.Print(m)
}

type Person struct {
	Name string
	Age  int
}

type Employee struct {
	*Person // 匿名字段，指针类型
	Salary  float64
}

func mainRuntttt() {
	emp := Employee{
		Person: &Person{Name: "Alice", Age: 30},
		Salary: 50000,
	}

	// 直接访问匿名字段的字段
	fmt.Println(emp.Name) // 输出: Alice
	fmt.Println(emp.Age)  // 输出: 30

	// 也可以直接访问匿名字段的方法（如果有）
	// 例如：emp.SomeMethod()
}
